package gui.panel_new;

import enums.FileFilterEnum;
import enums.URLEnum;
import j_util.Utiles;

import javax.help.HelpBroker;
import javax.help.HelpSet;
import javax.help.JHelpContentViewer;
import javax.help.JHelpNavigator;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.io.File;
import java.net.URL;
/*

    This file is part of Logica-Logike.

    Logica-Logike is free software: you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License as published by
    the Free Software Foundation version 3 of the License.

    Logica-Logike is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public License
    along with Logica-Logike.  If not, see <http://www.gnu.org/licenses/>.

 */
/**
 * @author Jose Martin Rozanec;
 */
public class HelpPanel extends OpenSavePanel {
    private String helpSetPath;

    public HelpPanel(String helpSetPath, JButton saveButton, JButton openButton, JFileChooser fileChooser) {
        this.saveButton = saveButton;
        this.openButton = openButton;
        this.fileChooser = fileChooser;
        this.helpSetPath = helpSetPath;
        fileFilter = FileFilterEnum.DEFAULT;
        init();
    }

    private void init() {
        //BEGINNING OF JAVA HELP BLOCK
        HelpSet hs = null;
        final HelpBroker hb;
        // open HelpSet, send console message
        URL hsURL = null;
        try {
            hsURL = new URL((new File(".")).toURI().toURL(), helpSetPath);
//            hsURL = new URL(helpSetPath);
            hs = new HelpSet(null, hsURL);
            System.out.println("Found help set at " + hsURL);
        }
        catch (Exception ee) {
            ee.printStackTrace();
            System.out.println("HelpSet not found");
            System.out.println("" + hsURL.toString());
            System.exit(0);
        }

        // create HelpBroker from HelpSet
        hb = hs.createHelpBroker();
        JHelpContentViewer contentViewer = new JHelpContentViewer(hs);
        contentViewer.setPreferredSize(new Dimension(520, 650));//525, 660
        // add a navigator with a table of contents view
        JHelpNavigator toc = (JHelpNavigator) hs.getNavigatorView("TOC").createNavigator(contentViewer.getModel());

        Dimension navigatorDimension = new Dimension(152, 612);
        toc.setPreferredSize(navigatorDimension);
        JHelpNavigator index = (JHelpNavigator) hs.getNavigatorView("Index").createNavigator(contentViewer.getModel());
        index.setPreferredSize(navigatorDimension);
        JHelpNavigator search = (JHelpNavigator) hs.getNavigatorView("Search").createNavigator(contentViewer.getModel());
        hb.setCurrentID("introduccion");
        search.setPreferredSize(navigatorDimension);
        // add the components to the layout
        JTabbedPane tabbedPane = new JTabbedPane();
//        tabbedPane.addTab("Indice", index);
        tabbedPane.addTab("Indice", toc);//tabla de contenidos
        tabbedPane.addTab("Busqueda", search);
        //END OF JAVA HELP BLOCK

        setLayout(new GridBagLayout());
        GridBagConstraints gridBagConstraints = new GridBagConstraints();
        gridBagConstraints.gridwidth = 1;
        gridBagConstraints.gridheight = 1;
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 1;
        add(tabbedPane, gridBagConstraints);
        gridBagConstraints.gridwidth = 3;
        gridBagConstraints.gridx = 2;
        add(contentViewer, gridBagConstraints);
//        setPreferredSize(new Dimension(600,600));
    }

    protected void setSaveActionListener() {
        class SaveSylogismAction extends AbstractAction {
            public SaveSylogismAction() {
                super("", Utiles.createImageIcon(URLEnum.getReference(URLEnum.SAVE_AS)));
            }

            public void actionPerformed(ActionEvent e) {

            }
        }
        saveButton.setAction(new SaveSylogismAction());
    }

    protected void setSaveButtonEnabled() {
        saveButton.setEnabled(false);
    }

    protected void setOpenActionListener() {
        class OpenHelpAction extends AbstractAction {
            public OpenHelpAction() {
                super("", Utiles.createImageIcon(URLEnum.getReference(URLEnum.OPEN)));
            }

            public void actionPerformed(ActionEvent e) {

            }
        }
        openButton.setAction(new OpenHelpAction());
    }

    protected void setOpenButtonEnabled() {
        openButton.setEnabled(false);
    }

    protected void setFocusOnComponent() {
        //remains unimplemented...
    }
}
